#region MIT Licence
/*
 * Copyright (C) 2014 PdfCreative
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom 
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#endregion

using System;

using PdfCreative.Pdf.Writer.Utilities;

namespace PdfCreative.Pdf.Writer
{
    /// <summary>
    /// The PdfResourceReference class represents a named reference to an object in the PDF stream. It is used
    /// to include the object into a page as a resource.
    /// </summary>
    [Serializable]
    public abstract class PdfResourceReference
    {
        // Private fields
        // ==============
        #region Private fields
        private PdfObjectReference _objectReference;
        private string _identifier;
        #endregion



        // Public properties
        // =================
        #region Public properties
        /// <summary>
        /// Retrieves the identifier for this resource.
        /// </summary>
        public string Identifier
        {
            get { return _identifier; }
        }

        /// <summary>
        /// Retrieves the object reference for this resource.
        /// </summary>
        public PdfObjectReference ObjectReference
        {
            get { return _objectReference; }
        }

        /// <summary>
        /// Retrieves a string that indicates the resource's type - this string will be used in the page's
        /// resources dictionary.
        /// </summary>
        public abstract string ResourceType
        {
            get;
        }
        #endregion



        // Object overrides
        // ================
        #region Object overrides
        /// <summary>
        /// Retrieves a string representation of the resource reference.
        /// </summary>
        /// <returns>The string representation</returns>
        public override string ToString()
        {
            return String.Format("/{0} {1}", this.Identifier, PdfUtilities.GetPdfStringValue(this.ObjectReference));
        }
        #endregion



        // Public Constructor
        // ==================
        #region Public Constructor
        /// <summary>
        /// Constructs a new PdfResourceReference instance.
        /// </summary>
        /// <param name="obj">The PDF object that this resource refers to.</param>
        /// <param name="identifier">The identifier that the object will be known as in the current page</param>
        /// <exception cref="ArgumentException">The obect reference and identifier cannot be Null or empty.</exception>
        public PdfResourceReference(PdfObjectReference obj, string identifier)
        {
            if (null == obj) throw new ArgumentNullException("obj");
            if (obj.IsEmpty()) throw new ArgumentException("The object reference can not be empty", "obj");
            if (string.IsNullOrEmpty(identifier)) throw new ArgumentException("The identifier cannot be null or empty", "identifier");

            _objectReference = obj;
            _identifier = identifier;
        }

        #endregion

    } // PdfResourceReference class
}
